package tests.search.artistalias;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.nanotek.lucene.index.Index;
import org.nanotek.lucene.index.info.FieldStat;
import org.nanotek.lucene.search.local.IndexSearcherProvider;
import org.nanotek.lucene.search.local.LocalSearcherService;
//import org.nanotek.query.QueryResult;
//import org.springframework.batch.core.Job;
//import org.springframework.batch.core.JobParametersBuilder;
//import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ArtistAliasIndexSearcherTest {

	ApplicationContext ctx; 
	Logger log = Logger.getLogger(ArtistAliasIndexSearcherTest.class);
	@Before
	public void setUp() throws Exception {
		try { 
			ctx = new ClassPathXmlApplicationContext(new String[] {
					"spring-index-searchers/index-reader-configuration_al.xml"});
		}catch (Exception ex) 
		{ 
			ex.printStackTrace();
		}
	}

	@After
	public void tearDown() throws Exception {
	}

	@SuppressWarnings("unused")
	@Test
	public void testSearcherService() {
		LocalSearcherService searcherService = (LocalSearcherService) ctx.getBean("searcherService");
//		Index index = (Index) ctx.getBean("index");
//		searcherService.createIndexSearcher(index);
		Index index = (Index) ctx.getBean("index");
		searcherService.search("rec*");
//		System.out.println("");
//		System.err.println("Result Class " + result.getClass());
//		assertTrue(result  != null);//("Not yet implemented");
	}

	@Test
	@Ignore
	public void testSearcherProvider()
	{ 
		IndexSearcherProvider indexSearcherProvider = (IndexSearcherProvider) ctx.getBean("indexSearcherProvider");
		Index index = (Index) ctx.getBean("index");
		FieldStat stat = indexSearcherProvider.getFieldStat(index, "name");
		List<String> fields = indexSearcherProvider.getFieldNames(index);
		Iterator <String> it = fields.iterator();
			while (it.hasNext())
				log.debug(it.next());
	}
	
}
